//
//  ZCRaisePayView.m
//  zctx
//
//  Created by apple on 15/12/1.
//  Copyright © 2015年 sanliang. All rights reserved.
//

#import "ZCRaisePayView.h"
@interface ZCRaisePayView()

@property (nonatomic,strong)UIButton *button;
@end
@implementation ZCRaisePayView

- (id)init {
    // Initialization code
    if (self = [super init]) {
        
    }
    return self;
}

-(void)initMoneyView{
    
    //    self.backgroundColor = [UIColor orangeColor];
    
    CGFloat xWidth = SCREEN_WIDTH-100;
    NSLog(@"sssss =%f",xWidth);
    
    CGFloat buttonW;
    if (IS_IPHONE_5 ||IS_IPHONE_4_OR_LESS) {
        buttonW = 50;
    }else{
        buttonW = 60;
    }
    CGFloat buttonH = 30;
    CGFloat marge = 10;
    
    for (int i = 0 ; i < _titleButtonArray.count; i++) {
        NSInteger index = i % 4;
        NSInteger page = i / 4;
        // 圆角按钮
        self.button= [UIButton buttonWithType:UIButtonTypeCustom];
        
        self.button.frame = CGRectMake(index * (buttonW+marge), page  * (buttonH + marge)+5, buttonW, buttonH);
        self.button.tag = i;
        [self.button setTitle:_titleButtonArray[i] forState:UIControlStateNormal];
        //        self.button.layer.cornerRadius = 3;
        //        self.button.layer.borderWidth = 1;
        //        self.button.layer.borderColor = [UIColor colorWithHexString:@"#a5a5a5"].CGColor;
        if (i==0) {
            [self.button setSelected:YES];
            self.selectButton = self.button;
            //            self.button.layer.borderColor = [UIColor colorWithHexString:@"#03Ab9e"].CGColor;
        }
        [self.button setTitleColor:[UIColor colorWithHexString:@"#a5a5a5"] forState:UIControlStateNormal];
        [self.button setTitleColor:[UIColor colorWithHexString:@"#03Ab9e"] forState:UIControlStateSelected];
        [self.button setBackgroundImage:[UIImage imageNamed:@"pay_button_select_n"] forState:UIControlStateNormal];
        [self.button setBackgroundImage:[UIImage imageNamed:@"pay_button_select_y"] forState:UIControlStateSelected];
        
        self.button.titleLabel.font = [UIFont systemFontOfSize:15];
        [self.button addTarget:self action:@selector(moneyButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.button];
        [self.buttonArray addObject:self.button];
    }
}
-(void)moneyButtonClick:(UIButton *)sender{
    
    if (self.selectButton != sender) {
        self.selectButton.selected = NO;
        //        self.selectButton.layer.borderColor = [UIColor colorWithHexString:@"#a5a5a5"].CGColor;
        //        sender.layer.borderColor = [UIColor colorWithHexString:@"#03Ab9e"].CGColor;
        self.selectButton = sender;
    }
    self.selectButton.selected = YES;
    self.moneyButtonClik(self.selectButton.tag,self.selectButton.titleLabel.text);
    
}

-(void)setTitleButtonArray:(NSArray *)titleButtonArray{
    _titleButtonArray = titleButtonArray;
    [self initMoneyView];
}
-(void)selectButtonAllNo{
    self.selectButton.selected = NO;
//    self.selectButton.layer.borderColor = [UIColor colorWithHexString:@"#a5a5a5"].CGColor;
}

@end
